package com.catty.consum.subscribe;

import java.util.List;
import java.util.Map;
import java.util.Random;

public class ServiceSubscribeHelper {

	private static final String DEFAULT_ADDRESS_STR = "127.0.0.1";
	
	public String getServiceServerAddress(String serviceName){
		
		String serviceTargetAddress = DEFAULT_ADDRESS_STR;
		
		SubscribeServiceBox ssb = SubscribeServiceBox.getInstance();

		Map<String,List<String>> serviceMapCenter = ssb.getServicesAddressMap();
		
		if(serviceMapCenter.containsKey(serviceName)){
			List<String> serverList = serviceMapCenter.get(serviceName);
			serviceTargetAddress = serverList.get(0);
		}
		
		System.out.println(serviceName+":"+serviceTargetAddress);
		return serviceTargetAddress;
	}
	
	private int getRandomServerAddress(int serverCount){
		
		Random random = new Random(serverCount);
		int selected = random.nextInt();
		
		return selected;
	}
	
}
